package com.example.myapplication;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;

// 聊天页面
public class Fragment1 extends Fragment {
    RecyclerView recyclerView;
    Myadapter2 ma;
    Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState){
        View view=inflater.inflate(R.layout.fragment1, container, false);
        context=this.getActivity();
        recyclerView=view.findViewById(R.id.recyclerView1);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // 把图片,专辑名和主打曲存入类Album
        List<Album> list = new ArrayList();

        Album thestorybegins = new Album(getRandomLengthName("The Story Begins"),
                R.drawable.tsb,
                getRandomLengthName("Like Ooh-Ahh"));
        list.add(thestorybegins);

        Album pagetwo = new Album(getRandomLengthName("Page Two"),
                R.drawable.cheerup,
                getRandomLengthName("CHEER UP"));
        list.add(pagetwo);

        Album lane1 = new Album(getRandomLengthName("Twicecoaster:Lane1"),
                R.drawable.tt,
                getRandomLengthName("TT"));
        list.add(lane1);

        Album lane2 = new Album(getRandomLengthName("Twicecoaster:Lane2"),
                R.drawable.knock,
                getRandomLengthName("Knock Knock"));
        list.add(lane2);

        Album signal = new Album(getRandomLengthName("Signal"),
                R.drawable.sig,
                getRandomLengthName("Signal"));
        list.add(signal);

        Album twicetagram = new Album(getRandomLengthName("Twicetagram"),
                R.drawable.likey,
                getRandomLengthName("Likey"));
        list.add(twicetagram);

        Album merryhappy = new Album(getRandomLengthName("Merry&Happy"),
                R.drawable.mh,
                getRandomLengthName("Heart Shaker"));
        list.add(merryhappy);

        Album whatislove = new Album(getRandomLengthName("What Is Love"),
                R.drawable.wil,
                getRandomLengthName("What is Love"));
        list.add(whatislove);

        Album summernights = new Album(getRandomLengthName("Summer Nights"),
                R.drawable.sn,
                getRandomLengthName("Dance The Night Away"));
        list.add(summernights);

        Album yesoryes = new Album(getRandomLengthName("YES or YES"),
                R.drawable.yoy,
                getRandomLengthName("YES or YES"));
        list.add(yesoryes);

        Album fancyyou = new Album(getRandomLengthName("FANCY YOU"),
                R.drawable.fancy,
                getRandomLengthName("FANCY"));
        list.add(fancyyou);

        Album feelspecial = new Album(getRandomLengthName("Feel Special"),
                R.drawable.fs,
                getRandomLengthName("Feel Special"));
        list.add(feelspecial);

        Album moremore = new Album(getRandomLengthName("MORE&MORE"),
                R.drawable.mm,
                getRandomLengthName("MORE & MORE"));
        list.add(moremore);

        Album eyeswideopen = new Album(getRandomLengthName("Eyes Wide Open"),
                R.drawable.ewo,
                getRandomLengthName("I CAN'T STOP ME"));
        list.add(eyeswideopen);

        Album tasteoflove = new Album(getRandomLengthName("Taste Of Love"),
                R.drawable.tol,
                getRandomLengthName("Alcohol-Free"));
        list.add(tasteoflove);

        Album formulaoflove = new Album(getRandomLengthName("Formula Of Love:O+T=<3"),
                R.drawable.fol,
                getRandomLengthName("SCIENTIST"));
        list.add(formulaoflove);

        Album between12 = new Album(getRandomLengthName("BETWEEN 1&2"),
                R.drawable.ttt,
                getRandomLengthName("Talk that Talk"));
        list.add(between12);

        Album readytobe = new Album(getRandomLengthName("READY TO BE"),
                R.drawable.rtb,
                getRandomLengthName("SET ME FREE"));
        list.add(readytobe);

        // 适配器
        ma=new Myadapter2(list,context);
        recyclerView.setAdapter(ma);

        return view;
    }
    // 将专辑名和主打曲转换为string
    private String getRandomLengthName(String str){
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 1; i++) {
            builder.append(str);
        }
        return builder.toString();
    }
}
